package com.nhjf.service.impl.teachers;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nhjf.dao.system.UserDao;
import com.nhjf.dao.teachers.ArtPicturesDao;
import com.nhjf.model.system.User;
import com.nhjf.model.teachers.ArtPictures;
import com.nhjf.pojo.dto.result.ServiceResultDto;
import com.nhjf.pojo.qo.teachers.ArtPicturesQo;
import com.nhjf.service.impl.BaseServiceImpl;
import com.nhjf.service.teachers.ArtPicturesService;
@Transactional
@Service("artPicturesService")
public class ArtPicturesServiceImpl extends BaseServiceImpl<ArtPictures, ArtPicturesQo, ArtPicturesDao> implements ArtPicturesService{

	@Autowired
	private ArtPicturesDao artPicturesDao;
	@Autowired
	private UserDao userDao;
	@Override
	protected ArtPicturesDao getDao() {
		// TODO Auto-generated method stub
		return artPicturesDao;
	}
	@Override
	public ServiceResultDto createArtPictures(String artPicturesUrl, String artName, int width, int height,
			Long userId,Long typeOne,Long typeTwo) {
		// TODO Auto-generated method stub
        ServiceResultDto resultDto = new ServiceResultDto();
        ArtPictures artPictures=new ArtPictures();
        if(StringUtils.isEmpty(artPicturesUrl)){
            resultDto.setSuccess(false);
            resultDto.setResultMessage("图片为空");
            return resultDto;
        }
        artPictures.setArtPicturesUrl(artPicturesUrl);
        if(StringUtils.isEmpty(artName)){
            resultDto.setSuccess(false);
            resultDto.setResultMessage("简介为空");
            return resultDto;
        }
        if(userId==null){
            resultDto.setSuccess(false);
            resultDto.setResultMessage("用户为空");
            return resultDto;
        }
        artPictures.setArtName(artName);
        artPictures.setWidth(width);
        artPictures.setHeight(height);
        User user=userDao.get(userId);
        user.setId(userId);
        artPictures.setUser(user);
        artPictures.setCreatTime(new Date());
        artPictures.setUserType(user.getIsRole());
        artPictures.setTypeOne(typeOne);
        artPictures.setTypeTwo(typeTwo);
        artPicturesDao.save(artPictures);
        resultDto.setSuccess(true);
        resultDto.setResultMessage("创建成功");
        return resultDto;
	}

}
